//将Buffer转化为JSON对象
var buf = new Buffer("earl tech welcome to you ");

console.log(buf.toJSON());


//缓冲区合并的代码
//利用concat()可自由拼接字符串
var buf1 = new Buffer("everything is ok ");

var bufAll = Buffer.concat([buf,buf1,buf1]);

console.log(bufAll.toString());



//缓冲区比较compare
var same = buf.compare(buf1);
console.log(same);  //  返回 -1  表示不同
var same1 = buf.compare(buf);
console.log(same1);  //返回0   表示相同


//拷贝缓冲区  copy
var buf2 = new Buffer("new");
buf2.copy(buf);
console.log(buf2.toString());
console.log(buf.toString());


//裁剪缓冲区  slice
var newBuf = buf1.slice(5,10);
console.log(newBuf.toString());

//缓冲区长度
console.log(newBuf.length);
